#include "EmotionWindow.h"
#include "ui_EmotionWindow.h"

EmotionWindow::EmotionWindow(QWidget *parent): 
	QWidget(parent),
	ui(new Ui::EmotionWindow())
{
	ui->setupUi(this);

	setWindowFlags(Qt::WindowType::SubWindow | Qt::WindowType::FramelessWindowHint);
	setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose);
	setAttribute(Qt::WidgetAttribute::WA_TranslucentBackground);

	initControl();
}

EmotionWindow::~EmotionWindow()
{
	delete ui;
}

void EmotionWindow::paintEvent(QPaintEvent * event)
{	
	QStyleOption styleOption;
	styleOption.init(this);

	QPainter painter;

	style()->drawPrimitive(
		QStyle::PrimitiveElement::PE_Widget,
		&styleOption,
		&painter,
		this
	);

	__super::paintEvent(event);
}

void EmotionWindow::addEmotion(int num)
{
	hide();

	emit signalEmotionItemClicked(num);
	emit signalEmotionWindowHide();
}

void EmotionWindow::initControl()
{
	CommonUtils::loadStyleSheet(this, "EmotionWindow");

	int emotionR = 12;
	int emotionC = 14;
	for (int i = 0; i < emotionR; ++i) {
		for (int j = 0; j < emotionC; ++j) {
			EmotionLabelItem *item = new EmotionLabelItem(this);
			item->setEmotionName(i*emotionC + j);

			ui->gridLayout->addWidget(item, i, j);

			connect(item, SIGNAL(signalEmotionClicked(int)),
				this, SLOT(addEmotion(int)));
		}
	}
}
